package cn.sangyy.user.controller;

import cn.sangyy.basic.utils.AjaxResult;
import cn.sangyy.user.dto.AccountLoginDto;
import cn.sangyy.user.dto.PhoneCodeLoginDto;
import cn.sangyy.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author SangYY
 * @date: 2023/06/02/22:55
 * 用户登录
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    /**
    * @author Sangyy
    * 账号（手机/用户名/邮箱）密码登录
    */
    @PostMapping("/accountLogin")
    public AjaxResult accountLogin(@RequestBody @Valid AccountLoginDto dto){
        Map<String, Object> result = loginService.accountLogin(dto);
        return AjaxResult.me().setResultObj(result);
    }
    /**
    * @author Sangyy
    * 手机验证码登录
    */
    @PostMapping("/phoneCodeLogin")
    public AjaxResult phoneCodeLogin(@RequestBody @Valid PhoneCodeLoginDto dto){
        Map<String, Object> result = loginService.phoneCodeLogin(dto);
        return AjaxResult.me().setResultObj(result);
    }
    /**
    * @author Sangyy
    * 微信登录
    */
    @PostMapping("/wechatLogin")
    public AjaxResult wechatLogin(@RequestBody Map<String,Object> map){
        Map<String, Object> result = loginService.wechatLogin(map);
        return AjaxResult.me().setResultObj(result);
    }

}
